key = {
		maj: false,
		right: false,
		left: false,
		space: false,
};

state = {
		walk: false,
		run: false,
		jump: false,
};



function keyDown(e) {
	if (e.keyCode == 39 || e.keyCode == 68) {
		key.right = true;		
	} else if (e.keyCode == 16) {
		key.maj = true;
	} else if (e.keyCode == 37 || e.keyCode == 81) {
		key.left = true;
	}
	process();
}

function keyUp(e) {
	if (e.keyCode == 39 || e.keyCode == 68) {
		key.right = false;
	} else if (e.keyCode == 16) {
		key.maj = false;
	} else if (e.keyCode == 37 || e.keyCode == 81) {
		key.left = false;
	}
	process();
}

function process() {
	if ((key.right == true || key.left == true) && key.maj == false) {
		if (state.walk == false) {
			kirby.f = 0;
			kirby.p = 0;
			state.walk = true;
		}
		if (state.run == true) {
			state.run = false;
		}
		anim = kirby.walk;
	} else if ((key.right == true || key.left == true) && key.maj == true) {
		if (state.run == false) {
			kirby.f = 0;
			kirby.p = 0;
			state.run = true;
		}
		if (state.walk == true) {
			state.walk = false;
		}
		anim = kirby.run;
	} else {
		kirby.f = 0;
		kirby.p = 0;
		walk = false;
		run = false;
		anim = kirby.stand;
	}
}